package si.wasu.trik;

import si.wasu.highscores.Highscore;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class Pavza extends Activity {

	static boolean finalLevel=false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_pavza);
		
		if(LevelListener.konec) {
			//ne prikazi nadaljuj gumba :P
			Button b=(Button) findViewById(R.id.continueButton);
			b.setVisibility(View.GONE);
			LevelListener.konec=false;
		}
		
		Highscore hs=new Highscore(this.getApplicationContext());
		int tocke=hs.getCurrentScore();
		TextView score=(TextView) findViewById(R.id.scoreText);
		score.setText(getResources().getString(R.string.tocke)+" "+String.valueOf(tocke));
		
		int openLevel=hs.getOpenLevel();
		openLevel++;
		if(openLevel<=LevelListener.zadnjiZGumbom) {
			hs.setOpenLevel(openLevel);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.pavza, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		Intent intent = new Intent(this, MenuActivity.class);
		startActivity(intent);
	}
	
	public void success(View v) {
		Intent intent = null;
		Highscore hs = new Highscore(getApplicationContext());
		int cur=Integer.parseInt(LevelListener.level.split(" ")[1]);
		
		switch (v.getId()) {
		case R.id.continueButton: 
			cur++;
			if(cur<=3) {
				hs.setOpenLevel(cur);
				LevelListener.level="Nivo "+cur;
			}
			else {
				cur=3;
			}
			
			if(cur==LevelListener.zadnjiZGumbom){
				LevelListener.konec=true;
			}
			else {
				LevelListener.konec=false;
			}
		case R.id.restartButton:
			intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			break;
		case R.id.menuButton:
			intent = new Intent(this, MenuActivity.class);
			startActivity(intent);
			break;
		}
	}
}
